package cn.sollyu.SDManager;

import java.io.File;
import java.util.HashMap;

import cn.sollyu.SDManger.R;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

public class ViewAlertDialog extends AlertDialog.Builder
{
//	private Context context;
//	private HashMap<String, Object> nowSelectHashMap;
	
	protected ViewAlertDialog(Context context,HashMap<String, Object> hashMap) {
		super(context);

//		nowSelectHashMap = hashMap;
		
		LayoutInflater layoutInflater = LayoutInflater.from(context);
		View view = layoutInflater.inflate(R.layout.view_activity, null);
		
		setTitle((String)hashMap.get(context.getString(R.string.hashMapName)));
		setIcon((Integer) hashMap.get(context.getString(R.string.hashMapIcon)));

		((TextView)view.findViewById(R.id.view_activity_textView_info)).setText((String)hashMap.get(context.getString(R.string.hashMapInfo)));
		((TextView)view.findViewById(R.id.view_activity_textView_dele)).setText((String)hashMap.get(context.getString(R.string.hashMapDel)));
		((TextView)view.findViewById(R.id.view_activity_textView_soft)).setText((String)hashMap.get(context.getString(R.string.hashMapSoftware)));
		
		FileManagerService fileManagerService =  new FileManagerService(context, hashMap.get(context.getString(R.string.hashMapPath)).toString());
		File file = new File(hashMap.get(context.getString(R.string.hashMapPath)).toString());
		try
		{
			if (file.isDirectory()) {
				((TextView)view.findViewById(R.id.view_activity_textView_size)).setText(fileManagerService.FormetFileSize(fileManagerService.getFileSize(file)) );
			}
			else {
				((TextView)view.findViewById(R.id.view_activity_textView_size)).setText(fileManagerService.FormetFileSize(fileManagerService.getFileSizes(file)) );
			}
		} catch (Exception e)
		{
			e.printStackTrace();
		}
		
		String[] indexStrings = context.getResources().getStringArray(R.array.edit_activity_spinner_index);
		TextView indexTextView = (TextView)view.findViewById(R.id.view_activity_textView_index);
		switch (new  Integer( (String)hashMap.get(context.getString(R.string.hashMapIndex)))) {
			case 1:
				indexTextView.setText(indexStrings[0]);
				indexTextView.setTextColor(Color.GREEN);
				break;
			case 2:
				indexTextView.setText(indexStrings[1]);
				indexTextView.setTextColor(Color.YELLOW);
				break;
			case 3:
				indexTextView.setText(indexStrings[2]);
				indexTextView.setTextColor(Color.RED);
				break;
			case 0:
				indexTextView.setText(context.getString(R.string.view_actity_text_unknow_index));
				indexTextView.setTextColor(Color.GRAY);
				break;
			default:
				break;
		}
		
		setView(view);
		
		
		
	}


	
	
	
}
